using System.Configuration;

namespace FU.Capstones.IMS.Services.Common
{
    public static class ConfigUtilities
    {
        public static string GetStringKey(string keyName, string defaultValue)
        {
            string value = ConfigurationManager.AppSettings[keyName];
            return string.IsNullOrEmpty(value) ? defaultValue : value;
        }

        public static int GetIntKey(string keyName, int defaultValue)
        {
            int returnValue;
            return int.TryParse(ConfigurationManager.AppSettings[keyName], out returnValue) ? returnValue : defaultValue;
        }

        public static string GetConnectionString(string keyName, string defaultConnectionString)
        {
            string value = ConfigurationManager.ConnectionStrings[keyName].ConnectionString;
            return string.IsNullOrEmpty(value) ? defaultConnectionString : value;
        }
    }
}